<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>新增推广URL</title>
</head>
<body>



<div class="container">


        <div class="comm_crub">
            <span class="now_crub">新增推广URL</span>
        </div>

        <div class="comm_content">

            <div  class="search-box">
                <form id="searchForm" class="form-inline" onsubmit="return false;">
                    <div style="position:relative">
                        <span >
                        	<span style='width:150px;text-align:right'>
                            推广URL:
                            </span>
                            <input id="tuiguang_url" class="form-control input-sm"  type="text"  value="" style="width:440px;" maxlength=150>
                        </span><br />
                        <span >
                        	<span style='width:150px;text-align:right'>
                            渠道 KEY1:
                            </span>
                            <select class="form-control input-sm" id='key1'>
                            	<option value='0'>请选择</option>
                            	<!--{foreach from=$item_array item=item_array_info}-->
                            		<option value="<!--{$item_array_info.itemID}-->,<!--{$item_array_info.itemName}-->"><!--{$item_array_info.itemName}--></option>
                            	<!--{/foreach}--> 
                            </select>
                        </span><br />
                        <span >
                        	<span style='width:150px;text-align:right'>
                        	子渠道 KEY2:
                        	</span>
                        	<input id="key2" class="form-control input-sm"  type="text"  value="" style="width:140px">                     	
                        </span><br />
                        <span >
                        	<span style='width:150px;text-align:right'>
                        	渠道 KEY3:
                        	</span>
                        	<input id="key3" class="form-control input-sm"  type="text"  value="" style="width:140px">        
                        	             	
                        </span>
                        <span>
                            <input type="button" class="btn btn-primary" value="获取" onclick="coupon.get_number();">&nbsp;&nbsp;
                        </span><br />
                        <span>
                        	<span style='width:150px;text-align:right'>
                            有效期:
                            </span>
                            <input class="form-control input-sm w100" id="start_time"  value="" readonly="readonly"   type="text" />
                            ～
                           <input class="form-control input-sm w100" id="end_time"  value="" readonly="readonly" type="text" />                       
               
                        </span>



    
                </form>
                <div class="bottom_fixbox">
        			<div class="tac" style="background: #dddddd;">
           			 <input type="button" class="btn btn-primary" onclick="coupon.add();" value="保存" />&nbsp;&nbsp;&nbsp;
            		<input type="button" class="btn btn-default" onclick="E.closeWindows();" value="关闭" />
        		</div>
    </div>
            </div>

        

        </div>


</div>

<script type="text/javascript">


    var coupon = {


        add : function(){

        	//首先要判断推广url,key1-3 有效期是否填写
        		var url = $('#tuiguang_url').val();
        		var key1 = $('#key1').val();
        		var key2 = $('#key2').val();
        		var key3 = $('#key3').val();
        		var start_time = $('#start_time').val();
        		var end_time = $('#end_time').val();
        		var msg ='';
        		if(url==''){
        			msg+="请填写推广url<br />";
        		
        		}
        		
        		if( url.substring(0,7) !='http://' && url.substring(0,8) !='https://' ){
        			msg+="url开头请填写http://或https://<br />";
        		}
				//开始判断key1,key2,key3,start_time,end_time不能为空
				if(key1==0){
					msg+="key1不能为空<br />";
				}
				
				if(key2==''){
					msg+="key2不能为空<br />";
				}
				
				//if(key3==''){
				//	msg+="key3不能为空<br />";
				//}
				//if(start_time ==''){
				//	msg+="start_time不能为空<br />";
				//}
				//if(end_time ==''){
				//	msg+="end_time不能为空<br />";
				//}
        		if(msg !=''){
        			E.alert(msg);
        			return false;
        		}
				$.ajax({
		            url: "/invokingAjax-backend/system/promote.ajax?operFlg=2",
		            data: {
		            	url : url ,
        		 		key1 : key1,
        		 		key2 : key2,
						key3 : key3,
						start_time : start_time,
						end_time : end_time
		            },
		            type: "POST",
		            success: function(data){
						if(data ==2){
							E.alert('4个参数已经定义,请重新输入');
							return false;
						}
						if(data==1){
							E.alert('添加成功',2);
						  	coupon.search();
						
						
						}
						
		            }            
		        });        
        },
        //获取5位随机数字
        get_number : function (){
        	var number='';
        	for(var i = 0 ; i < 5 ; i++){
        		number+=parseInt(10*Math.random())
        	}
        	$('#key3').val(number)
        
        },

    };

	$('#start_time').datepicker();
    $('#end_time').datepicker();
</script>

</body>
</html>